<?php
/**
 * Description of event
 *
 * @author Henson
 */
class Event extends Base{
	
	private $eventTable = "tbl_event";
	
	public function updateEvent($updateArr, $eid)
	{
		$updateArr['update_time'] = time();
		$where = " where id=".$eid;
		return $this->db->update($updateArr, $this->eventTable, $where);
	}
	
	public function insertEvent($insertArr)
	{
		//$insertArr['aid'] = $aid;
		$insertArr['insert_time'] = time();
		$insertArr['del'] = '0';
		return $this->db->insert($insertArr, $this->eventTable);
	}
	
	public function delEvent($eid)
	{
		$updateArr = array(
			'del'			=> '1',
			'update_time'	=> time()
		);
		$where = " where id=".$eid;
		return $this->db->update($updateArr, $this->eventTable, $where);
	}
	
	public function getEventList($where, $orderBy='', $limit='')
	{
		$sql = "select * from {$this->eventTable} {$where} {$orderBy} {$limit}";
		$this->db->setQuery($sql);
		return $this->db->loadAssocList();
	}
	
	public function getEventByEid($eid)
	{
		$sql = "select * from {$this->eventTable} where id=".$eid;
		return $this->db->loadRow($sql);
	}
	
	public function getEventTotal()
	{
		$where = "where del='0'";
		return $this->getTotalNum($this->eventTable, $where);
	}
	
	public function dealEvent($eventRow)
	{
		 @$eventRow['start_time_show']	= date("F j, Y, g:i a", $eventRow['start_time']);
		 @$eventRow['end_time_show']	= date("F j, Y, g:i a", $eventRow['end_time']);
		 @$eventRow['start_time_b_show']= date("Y-m-d H:i:s", $eventRow['start_time']);
		 @$eventRow['end_time_b_show']	= date("Y-m-d H:i:s", $eventRow['end_time']);
		 @$eventRow['start_date']		= date("Y-m-d", $eventRow['start_time']);
		 @$eventRow['end_date']			= date("Y-m-d", $eventRow['end_time']);
		 @$eventRow['start_H']			= date("H", $eventRow['start_time']);
		 @$eventRow['end_H']			= date("H", $eventRow['end_time']);
		 @$eventRow['layout']			= '/uploadfile/layout/'.$eventRow['layout'];
		 @$eventRow['type_show']		= $eventRow['type'] == 0 ? 'not need' : 'need';
		 $eventRow['show']				= '1';
		 if(@$eventRow['start_time'] - time() < @$eventRow['limit_time'] * 3600 || @$eventRow["start_time"] <= time() || @$eventRow['cancel'] == '1')
		 {
			 $eventRow['show'] = '0';
		 }
		 return $eventRow;
	}
}

?>
